Skip to content

Conversation

@SergejSalnikov
Copy link
Contributor

@SergejSalnikov SergejSalnikov commented Nov 5, 2025

This is no longer required after #166255

@SergejSalnikov SergejSalnikov changed the title All file loc followup Remove unnessesary call to SM.getFileLoc when calling SM.getPresumedLoc. Nov 5, 2025
@SergejSalnikov SergejSalnikov changed the title Remove unnessesary call to SM.getFileLoc when calling SM.getPresumedLoc. Remove unnessesary call to SM.getFileLoc when calling SM.getPresumedLoc Nov 5, 2025
@SergejSalnikov SergejSalnikov changed the title Remove unnessesary call to SM.getFileLoc when calling SM.getPresumedLoc [clang] Remove unnessesary call to SM.getFileLoc when calling SM.getPresumedLoc Nov 5, 2025
@SergejSalnikov SergejSalnikov changed the title [clang] Remove unnessesary call to SM.getFileLoc when calling SM.getPresumedLoc [clang][SourceManager] Remove unnessesary call to getFileLoc when calling getPresumedLoc Nov 5, 2025
@SergejSalnikov SergejSalnikov changed the title [clang][SourceManager] Remove unnessesary call to getFileLoc when calling getPresumedLoc [clang][DebugInfo] Remove unnessesary call to SM.getFileLoc when calling SM.getPresumedLoc Nov 5, 2025
@SergejSalnikov SergejSalnikov marked this pull request as ready for review November 17, 2025 12:54
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. debuginfo labels Nov 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 17, 2025

@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-debuginfo

@llvm/pr-subscribers-clang

Author: Sergej Salnikov (SergejSalnikov)

Changes

This is no longer required after #166255


Full diff: https://github.com/llvm/llvm-project/pull/166544.diff

1 Files Affected:

  • (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+7-8)
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index ca579c915f49d..6c1e0038a4316 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -345,7 +345,7 @@ void CGDebugInfo::setLocation(SourceLocation Loc) {
   if (Loc.isInvalid())
     return;
 
-  CurLoc = CGM.getContext().getSourceManager().getFileLoc(Loc);
+  CurLoc = Loc;
 
   // If we've changed files in the middle of a lexical scope go ahead
   // and create a new lexical scope with file node if it's different
@@ -571,8 +571,9 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
     // with an absolute path.
     FileName = TheCU->getFile()->getFilename();
     CSInfo = TheCU->getFile()->getChecksum();
+    FID = SM.getFileID(Loc);
   } else {
-    PresumedLoc PLoc = SM.getPresumedLoc(SM.getFileLoc(Loc));
+    PresumedLoc PLoc = SM.getPresumedLoc(Loc);
     FileName = PLoc.getFilename();
 
     if (FileName.empty()) {
@@ -599,8 +600,7 @@ llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
     if (CSKind)
       CSInfo.emplace(*CSKind, Checksum);
   }
-  return createFile(FileName, CSInfo,
-                    getSource(SM, SM.getFileID(SM.getFileLoc(Loc))));
+  return createFile(FileName, CSInfo, getSource(SM, FID));
 }
 
 llvm::DIFile *CGDebugInfo::createFile(
@@ -655,7 +655,7 @@ unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) {
   if (Loc.isInvalid())
     return 0;
   SourceManager &SM = CGM.getContext().getSourceManager();
-  return SM.getPresumedLoc(SM.getFileLoc(Loc)).getLine();
+  return SM.getPresumedLoc(Loc).getLine();
 }
 
 unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc, bool Force) {
@@ -667,8 +667,7 @@ unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc, bool Force) {
   if (Loc.isInvalid() && CurLoc.isInvalid())
     return 0;
   SourceManager &SM = CGM.getContext().getSourceManager();
-  PresumedLoc PLoc =
-      SM.getPresumedLoc(Loc.isValid() ? SM.getFileLoc(Loc) : CurLoc);
+  PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc);
   return PLoc.isValid() ? PLoc.getColumn() : 0;
 }
 
@@ -6281,7 +6280,7 @@ void CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
                                             const StringLiteral *S) {
   SourceLocation Loc = S->getStrTokenLoc(0);
   SourceManager &SM = CGM.getContext().getSourceManager();
-  PresumedLoc PLoc = SM.getPresumedLoc(SM.getFileLoc(Loc));
+  PresumedLoc PLoc = SM.getPresumedLoc(Loc);
   if (!PLoc.isValid())
     return;
 

@SergejSalnikov
Copy link
Contributor Author

@AaronBallman, this is a follow up change for #166255

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM presuming precommit CI doesn't find any surprises

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category debuginfo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants